package ru.usu.gv.uicomponents;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author spupyrev
 * 05.11.2008
 */
public class UIViewTypeRegistry<T extends IUIViewType>
{
    protected static abstract class UIViewType implements IUIViewType
    {
        private String id;
        private String title;
        private String icon;

        public UIViewType(String id, String title, String icon)
        {
            this.id = id;
            this.title = title;
            this.icon = icon;
        }

        public String getId()
        {
            return id;
        }

        public String getTitle()
        {
            return title;
        }

        public String getIconUrl()
        {
            return icon;
        }
    }

    private Map<String, T> types = new LinkedHashMap<String, T>();

    protected void addType(T type)
    {
        types.put(type.getId(), type);
    }

    public List<String> getViewTypeIds()
    {
        return new ArrayList(types.keySet());
    }

    public T findViewType(String viewTypeId)
    {
        if (!types.containsKey(viewTypeId))
            throw new RuntimeException("Unkown view type '" + viewTypeId + "'");

        return types.get(viewTypeId);
    }

}
